﻿namespace NEvoWeb.Modules.NB_Store
{
    using DotNetNuke.Common.Utilities;
    using DotNetNuke.Entities.Portals;
    using DotNetNuke.Entities.Users;
    using DotNetNuke.Services.Mail;
    using System;
    using System.Collections;
    using System.Web;

    public class ClientController
    {
        public ArrayList GetUsers(int PortalID, string Filter)
        {
            return CBO.FillCollection(DataProvider.Instance().GetNB_Store_GetUsers(PortalID, Filter), typeof(NB_StoreUsersInfo));
        }

        public void LockUser(int Portalid, int UserId)
        {
            UserInfo userById = UserController.GetUserById(Portalid, UserId);
            if (userById != null)
            {
                userById.Membership.Approved = false;
                UserController.UpdateUser(Portalid, userById);
            }
        }

        public void ResetPassword(int PortalID, int UserId)
        {
            UserInfo userById = UserController.GetUserById(PortalID, UserId);
            if (userById != null)
            {
                UserController.ResetPassword(userById, "");
                DotNetNuke.Services.Mail.Mail.SendMail(userById, MessageType.PasswordReminder, (PortalSettings) HttpContext.Current.Items["PortalSettings"]);
            }
        }

        public void UnlockUser(int Portalid, int UserId)
        {
            UserInfo userById = UserController.GetUserById(Portalid, UserId);
            if (userById != null)
            {
                UserController.UnLockUser(userById);
            }
        }

        public void updateEmail(int PortalID, int UserID, string Email)
        {
            UserInfo userById = UserController.GetUserById(PortalID, UserID);
            if ((userById != null) && (userById.Email != Email))
            {
                userById.Email = Email;
                UserController.UpdateUser(PortalID, userById);
            }
        }
    }
}

